<!DOCTYPE html>
<!-- 
 在VS Code中快速生成HTML标准页面的快捷键:
 1. 输入 ! 或 html:5 然后按 Tab 键
 2. 输入 doc 然后按 Tab 键
 -->
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/react/18.2.0/umd/react.production.min.js"></script>
    <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
    <script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/babel-standalone/6.26.0/babel.min.js"></script>
  </head>
  <body>
    <div id="test"></div>
    <script type="text/babel">
      let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
      let arr2 = Array.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

      let newArr = arr.map((item) => {
        return item * 2;
      });
      let newArr2 = arr.map((item) => item * 2);
      let newArr3 = arr.filter((item) => item > 5);

      console.log(newArr, typeof newArr, newArr instanceof Array);
      console.log(`length()->`,newArr2.length, typeof newArr, newArr instanceof Array);
      console.log(`newArr3大于5`, newArr3, typeof newArr, newArr instanceof Array);
      console.log(arr);

      const map = new Map([[1, 2], [2, 4], [4, 8]]);
      Array.from(map); // [[1, 2], [2, 4], [4, 8]]

      const mapper = new Map([['1', 'a'], ['2', 'b']]);
      Array.from(mapper.values()); // ['a', 'b'];
      Array.from(mapper.keys()) // ['1', '2'];

      let array=Array.of(1,2,3,4,5,6);
      // find() ——【查找】查找数组中符合条件的元素,若有多个符合条件的元素，则返回第一个元素。
      const xx = (array.find(item=>(item>4))); //5 
      console.log('xx', xx);

      // 11.flat()——嵌套数组转一维数组
      console.log([1,[2,3],[4,5]].flat()); //[1, 2, 3, 4, 5]
      console.log([1,[2,[3,4]]].flat(1)); //[1, 2, [3,4]]
      console.log([1,[2,3,[4,[5,6]]]].flat(Infinity)); //[1, 2, 3, 4, 5, 6]
      console.log([1,,[2,,3]].flat()); //[1, 2, 3]

      // 12.flatMap()——先对数组中每个元素进行了的处理，再对数组执行 flat() 方法。
      console.log([1,2,,3].flatMap(i=>i*i)); //[1，4，9]

      // 17.reduce()  —计算数组元素相加后的总和
      let arrayxx = [1, 2, 3, 4]
      getSum = (total, item) => {
          return total + item;
      }
      console.log(arrayxx.reduce(getSum)); //10
      console.log(arrayxx.reduce(getSum,10)); //20
    </script>
  </body>
</html>
